{#
# This file is part of Zenodo.
# Copyright (C) 2015, 2016 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Zenodo is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zenodo; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
#}

{%- from "invenio_formatter/macros/meta.html" import meta_twittercard, meta_opengraph, meta_highwire -%}
{%- set meta_title = record.title|striptags -%}
{%- set meta_description = record.description|striptags -%}
{%- set meta_url = url_for('invenio_records_ui.recid', pid_value=pid.pid_value, _external=True) -%}
{%- set meta_authors = record.creators|map(attribute='name') -%}
{%- set meta_publication_date = record.publication_date|from_isodate -%}
{%- set files = record.files if current_user|has_record_perm(record, 'read-files') else [] %}

{%- if files | selectattr("type", "equalto", "pdf") | list | length is equalto 0 %}
  {% set pdf_url_meta_highwire = "" %}
{%- else %}
  {% set pdf_url_meta_highwire = url_for('invenio_records_ui.recid_files', pid_value=pid.pid_value, filename=files | selectattr("type", "equalto", "pdf") | first | attr("key"), _external=True) %}
{%- endif %}

{{- meta_highwire(
  meta_title,
  meta_description,
  authors=meta_authors,
  url=meta_url,
  doi=record.doi,
  keywords=record.keywords,
  publication_date=publication_date,
  pdf_url=pdf_url_meta_highwire
) }}
{{- meta_opengraph(meta_title, meta_description, url=meta_url) }}
{{- meta_twittercard(meta_title, meta_description) }}
    <link rel="canonical" href="{{ meta_url }}">

{%- for file in files or [] -%}
    {%- set file_url = url_for('invenio_records_ui.recid_files', pid_value=pid.pid_value, filename=file.key, _external=True) %}
    <link rel="alternate" type="{{file.mimetype}}" href="{{ file_url }}">
{%- endfor -%}
